<?php

    require_once dirname(dirname(__FILE__)) . '/config/config.php';
    require_once DOCUMENT_ROOT . DIR_SHARED_DAO . 'dao_bet_history.php';

    /**
     * User: Viet Anh
     * Date: 06/06/2014
     * Time: 19:56
     */
    class api_bet_history
    {

        public static function get_bet_history_of_user($user_id)
        {
            $dao_bet_history = new dao_bet_history();

            return $dao_bet_history->get_bet_history_of_user($user_id);
        }

        public static function delete_bet_history_with_id($bet_history_id)
        {
            $dao_bet_history = new dao_bet_history();
            return $dao_bet_history->delete($bet_history_id);
        }
        
        public static function get_result_bet_of_match($match_id, $bet_history_id)
        {
            $dao_bet_history = new dao_bet_history();

            $win_choice_id = $dao_bet_history->get_win_choice_id_of_match($match_id);
            $bet_history   = $dao_bet_history->get_bet_history($bet_history_id);
            if (empty($win_choice_id)) {
                return "Not ended";
            } elseif ($win_choice_id == $bet_history['choice_id']) {
                return "Won";
            } else {
                return "Lost";
            }
        }

        public static function get_result_money($result, $bet_amount, $profit_if_win)
        {
            if ($profit_if_win == 0) {
                $class = "text-warning";
                $money_text = "$ 0";
            } elseif ($result === "Won") {
                $class = "text-success";
                $money_text = "+ $$profit_if_win";
            } elseif ($result === "Lost") {
                $class = "text-danger";
                $money_text = "- $$bet_amount";
            } else {
                $class = "text-warning";
                $money_text = "Match not ended!";
            }
            $final_result = [
                'class' => $class,
                'money_text' => $money_text,
            ];
            return $final_result;
        }
    }